Various cleanups and fixes for PV-on-HVM drivers.
authorKeir Fraser <keir@xensource.com>
Wed, 4 Apr 2007 20:49:04 +0000 (21:49 +0100)
committerKeir Fraser <keir@xensource.com>
Wed, 4 Apr 2007 20:49:04 +0000 (21:49 +0100)
Signed-off-by: Keir Fraser <keir@xensource.com>
14 files changed:
linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c
linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c
linux-2.6-xen-sparse/drivers/xen/core/gnttab.c
linux-2.6-xen-sparse/drivers/xen/core/reboot.c
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypervisor.h
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/maddr.h
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/page.h
linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/maddr.h
linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/page.h
unmodified_drivers/linux-2.6/compat-include/xen/platform-compat.h
unmodified_drivers/linux-2.6/mkbuildtree
xen/arch/x86/hvm/hvm.c
xen/arch/x86/hvm/svm/svm.c
xen/arch/x86/hvm/vmx/vmx.c

index c052097889e392be3e1f53f14273d3f2fe11a6a0..195f06921a5186f98b7faaa51f6dd1f675a32684 100644 (file)
 #include <xen/xenbus.h>
 #include "common.h"
 
-#ifndef CONFIG_XEN 
-#define scrub_pages(_p,_n)
-#endif
-
 #ifdef CONFIG_PROC_FS
 static struct proc_dir_entry *balloon_pde;
 #endif
@@ -251,8 +247,6 @@ static int increase_reservation(unsigned long nr_pages)
        return 0;
 }
 
-extern void xen_invalidate_foreign_mappings(void);
-
 static int decrease_reservation(unsigned long nr_pages)
 {
        unsigned long  pfn, i, flags;
@@ -286,7 +280,7 @@ static int decrease_reservation(unsigned long nr_pages)
                                (unsigned long)v, __pte_ma(0), 0);
                        BUG_ON(ret);
                }
-#ifdef CONFIG_XEN
+#ifdef CONFIG_XEN_SCRUB_PAGES
                else {
                        v = kmap(page);
                        scrub_pages(v, 1);
@@ -306,13 +300,18 @@ static int decrease_reservation(unsigned long nr_pages)
        /* No more mappings: invalidate P2M and add to balloon. */
        for (i = 0; i < nr_pages; i++) {
                pfn = mfn_to_pfn(frame_list[i]);
-#ifdef CONFIG_XEN
                set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
-#endif
                balloon_append(pfn_to_page(pfn));
        }
 
-        xen_invalidate_foreign_mappings(); 
+#ifndef CONFIG_XEN
+       /* XXX Temporary hack. */
+       {
+               extern void xen_invalidate_foreign_mappings(void);
+               xen_invalidate_foreign_mappings(); 
+       }
+#endif
+
        set_xen_guest_handle(reservation.extent_start, frame_list);
        reservation.nr_extents   = nr_pages;
        ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
@@ -476,7 +475,7 @@ static int __init balloon_init(void)
        bs.current_pages = min(xen_start_info->nr_pages, max_pfn);
        totalram_pages   = bs.current_pages;
 #else 
-        bs.current_pages = totalram_pages; 
+       bs.current_pages = totalram_pages; 
 #endif
        bs.target_pages  = bs.current_pages;
        bs.balloon_low   = 0;
@@ -592,9 +591,9 @@ struct page **alloc_empty_pages_and_pagevec(int nr_pages)
 #ifdef CONFIG_XEN
                        ret = apply_to_page_range(&init_mm, vaddr, PAGE_SIZE,
                                                  dealloc_pte_fn, NULL);
-#else 
-                        /* cannot handle non-auto translate mode */
-                        ret = 1; 
+#else
+                       /* Cannot handle non-auto translate mode. */
+                       ret = 1;
 #endif
                }
 
index 2a263c0c75c40f7e7ba125feac9157e2a4ad2008..283e17c3b970c73a27f5786efc9dc1eee7b3f763 100644 (file)
@@ -661,9 +661,10 @@ void do_blkif_request(request_queue_t *rq)
                if (RING_FULL(&info->ring))
                        goto wait;
 
-               DPRINTK("do_blk_req %p: cmd %p, sec %lx, "
+               DPRINTK("do_blk_req %p: cmd %p, sec %llx, "
                        "(%u/%li) buffer:%p [%s]\n",
-                       req, req->cmd, req->sector, req->current_nr_sectors,
+                       req, req->cmd, (long long)req->sector,
+                       req->current_nr_sectors,
                        req->nr_sectors, req->buffer,
                        rq_data_dir(req) ? "write" : "read");
 
index 2b2d11f77b057b445f8152a16a375a64f5640922..07588d36a3b399eeff64fc5aaa46630b9ad01594 100644 (file)
@@ -407,13 +407,11 @@ grow_nomem:
 static unsigned int __max_nr_grant_frames(void)
 {
        struct gnttab_query_size query;
-       int rc = -1;
+       int rc;
 
        query.dom = DOMID_SELF;
 
-#ifdef CONFIG_XEN
        rc = HYPERVISOR_grant_table_op(GNTTABOP_query_size, &query, 1);
-#endif
        if ((rc < 0) || (query.status != GNTST_okay))
                return 4; /* Legacy max supported number of frames */
 
index aa6215c93ed86d2cf8cfbb706e97fa99363f14eb..ffe05f47df5388690950c7e212f57374120bac35 100644 (file)
@@ -9,6 +9,10 @@
 #include <xen/xenbus.h>
 #include <linux/kthread.h>
 
+#ifdef HAVE_XEN_PLATFORM_COMPAT_H
+#include <xen/platform-compat.h>
+#endif
+
 MODULE_LICENSE("Dual BSD/GPL");
 
 #define SHUTDOWN_INVALID  -1
index 9bc4554b968ef3125c492fe567827aad7b61ed90..e9cc015efb0c35434e54cfa2ad10c434aad7cc97 100644 (file)
@@ -122,6 +122,12 @@ void xen_destroy_contiguous_region(
 /* Turn jiffies into Xen system time. */
 u64 jiffies_to_st(unsigned long jiffies);
 
+#ifdef CONFIG_XEN_SCRUB_PAGES
+#define scrub_pages(_p,_n) memset((void *)(_p), 0, (_n) << PAGE_SHIFT)
+#else
+#define scrub_pages(_p,_n) ((void)0)
+#endif
+
 #include <asm/hypercall.h>
 
 #if defined(CONFIG_X86_64)
index 8f3b7d8298b95318e218c7abcc71864f46965a12..0f50556dd4d60c9723e97170283dc7aa1b67df66 100644 (file)
@@ -158,7 +158,7 @@ static inline paddr_t pte_machine_to_phys(maddr_t machine)
 #define pfn_to_mfn(pfn) (pfn)
 #define mfn_to_pfn(mfn) (mfn)
 #define mfn_to_local_pfn(mfn) (mfn)
-#define set_phys_to_machine(pfn, mfn) BUG_ON((pfn) != (mfn))
+#define set_phys_to_machine(pfn, mfn) ((void)0)
 #define phys_to_machine_mapping_valid(pfn) (1)
 #define phys_to_machine(phys) ((maddr_t)(phys))
 #define machine_to_phys(mach) ((paddr_t)(mach))
index 5f7e40d725d15262dd6b70963221e2ab9b0319a6..29d41fc96e5b01c579370c50a2cabf8838defd64 100644 (file)
 })
 #define HAVE_ARCH_FREE_PAGE
 
-#ifdef CONFIG_XEN_SCRUB_PAGES
-#define scrub_pages(_p,_n) memset((void *)(_p), 0, (_n) << PAGE_SHIFT)
-#else
-#define scrub_pages(_p,_n) ((void)0)
-#endif
-
 #ifdef CONFIG_X86_USE_3DNOW
 
 #include <asm/mmx.h>
index 2bbac7cb4e811b45518af92748c7784bd541603d..cefd6e0b61bf77bb4a957b493bab6aa5c1d56284 100644 (file)
@@ -140,7 +140,7 @@ static inline paddr_t pte_machine_to_phys(maddr_t machine)
 #define pfn_to_mfn(pfn) (pfn)
 #define mfn_to_pfn(mfn) (mfn)
 #define mfn_to_local_pfn(mfn) (mfn)
-#define set_phys_to_machine(pfn, mfn) BUG_ON((pfn) != (mfn))
+#define set_phys_to_machine(pfn, mfn) ((void)0)
 #define phys_to_machine_mapping_valid(pfn) (1)
 #define phys_to_machine(phys) ((maddr_t)(phys))
 #define machine_to_phys(mach) ((paddr_t)(mach))
index 6340e6e6d61c17488bbc47d281dc556909676747..2f9ef2a15b00dbe08271c39d52d1378d3fd3932d 100644 (file)
 })
 #define HAVE_ARCH_FREE_PAGE
 
-#ifdef CONFIG_XEN_SCRUB_PAGES
-#define scrub_pages(_p,_n) memset((void *)(_p), 0, (_n) << PAGE_SHIFT)
-#else
-#define scrub_pages(_p,_n) ((void)0)
-#endif
-
 /* PAGE_SHIFT determines the page size */
 #define PAGE_SHIFT     12
 #ifdef __ASSEMBLY__
index 7493ddf3820ff56590a74f7491814163734fb1d9..d327d703ead41951eba751c35ca451f4bd0f38c0 100644 (file)
 #define NET_IP_ALIGN 0
 #endif
 
+#if defined(_LINUX_SKBUFF_H) && !defined(CHECKSUM_HW)
+#define CHECKSUM_HW CHECKSUM_PARTIAL
+#endif
+
 #if defined(_LINUX_ERR_H) && !defined(IS_ERR_VALUE)
 #define IS_ERR_VALUE(x) unlikely((x) > (unsigned long)-1000L)
 #endif
@@ -76,6 +80,10 @@ extern char *kasprintf(gfp_t gfp, const char *fmt, ...)
        __attribute__ ((format (printf, 2, 3)));
 #endif
 
+#if defined(_LINUX_SYSRQ_H) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)
+#define handle_sysrq(x,y,z) handle_sysrq(x,y)
+#endif
+
 /*
  * This variable at present is referenced by netfront, but only in code that
  * is dead when running in hvm guests. To detect potential active uses of it
index 31415928cdeb6d78c7dd442e00d3fb51fc05a4ce..b12da9b0861603e8fbb2c44ee330c7d1486fbd2f 100755 (executable)
@@ -50,7 +50,6 @@ i[34567]86)
     ln -sf ${XL}/include/asm-i386/mach-xen/asm/hypercall.h include/asm
     ln -sf ${XL}/include/asm-i386/mach-xen/asm/synch_bitops.h include/asm
     ln -sf ${XL}/include/asm-i386/mach-xen/asm/maddr.h include/asm
-    ln -sf ${XL}/include/asm-i386/mach-xen/asm/page.h include/asm
   ;;
 "ia64")
     ln -sf ${XL}/include/asm-ia64/hypervisor.h include/asm
index 66478c5800cbb83428b6ee644864edb77fb45975..c68341662faf1b15e43e058f587955668995363c 100644 (file)
@@ -531,25 +531,22 @@ int hvm_do_hypercall(struct cpu_user_regs *pregs)
 
     if ( (pregs->eax >= NR_hypercalls) || !hvm_hypercall_table[pregs->eax] )
     {
-        gdprintk(XENLOG_WARNING, "HVM vcpu %d:%d did a bad hypercall %d.\n",
-                current->domain->domain_id, current->vcpu_id,
-                pregs->eax);
+        if ( pregs->eax != __HYPERVISOR_grant_table_op )
+            gdprintk(XENLOG_WARNING, "HVM vcpu %d:%d bad hypercall %d.\n",
+                     current->domain->domain_id, current->vcpu_id, pregs->eax);
         pregs->eax = -ENOSYS;
         return 0;
     }
 
-    /* Install a canary value in regs->eip so can check for continuation */
-    pregs->eip |= 0xF; 
+    /* Check for preemption: EIP will be modified from this dummy value. */
+    pregs->eip = 0xF0F0F0FF;
 
     pregs->eax = hvm_hypercall_table[pregs->eax](
         pregs->ebx, pregs->ecx, pregs->edx, pregs->esi, pregs->edi);
 
-    /* XXX: pot fake IO instr here to inform the emulator to flush mapcache */
+    /* XXX: put fake IO instr here to inform the emulator to flush mapcache */
 
-    if( (pregs->eip & 0xF) == 0 ) /* preempted */
-        return 1; 
-
-    return 0; 
+    return (pregs->eip != 0xF0F0F0FF); /* preempted? */
 }
 
 #else /* defined(__x86_64__) */
@@ -620,13 +617,16 @@ int hvm_do_hypercall(struct cpu_user_regs *pregs)
     pregs->rax = (uint32_t)pregs->eax; /* mask in case compat32 caller */
     if ( (pregs->rax >= NR_hypercalls) || !hvm_hypercall64_table[pregs->rax] )
     {
-        gdprintk(XENLOG_WARNING, "HVM vcpu %d:%d did a bad hypercall %ld.\n",
-                current->domain->domain_id, current->vcpu_id,
-                pregs->rax);
+        if ( pregs->rax != __HYPERVISOR_grant_table_op )
+            gdprintk(XENLOG_WARNING, "HVM vcpu %d:%d bad hypercall %ld.\n",
+                     current->domain->domain_id, current->vcpu_id, pregs->rax);
         pregs->rax = -ENOSYS;
         return 0;
     }
 
+    /* Check for preemption: RIP will be modified from this dummy value. */
+    pregs->rip = 0xF0F0F0FF;
+
     if ( current->arch.paging.mode->guest_levels == 4 )
     {
         pregs->rax = hvm_hypercall64_table[pregs->rax](pregs->rdi,
@@ -643,7 +643,10 @@ int hvm_do_hypercall(struct cpu_user_regs *pregs)
                                                        (uint32_t)pregs->esi,
                                                        (uint32_t)pregs->edi);
     }
-    return 0; /* XXX SMH: fix for preempt here */
+
+    /* XXX: put fake IO instr here to inform the emulator to flush mapcache */
+
+    return (pregs->rip != 0xF0F0F0FF); /* preempted? */
 }
 
 #endif /* defined(__x86_64__) */
index 8b25f5019bba64e62050935dff18356f1eca809a..39c94bdb311ea9824409d2267b7dcd74036b324e 100644 (file)
@@ -2275,8 +2275,8 @@ asmlinkage void svm_vmexit_handler(struct cpu_user_regs *regs)
         inst_len = __get_instruction_length(v, INSTR_VMCALL, NULL);
         ASSERT(inst_len > 0);
         HVMTRACE_1D(VMMCALL, v, regs->eax);
-        if(hvm_do_hypercall(regs) == 0) /* not preempted */
-            __update_guest_eip(vmcb, inst_len);
+        if ( !hvm_do_hypercall(regs) )
+            __update_guest_eip(vmcb, inst_len); /* not preempted */
         break;
 
     case VMEXIT_CR0_READ:
index d7c700ca24336ccc884341ff3fa3789c6c2d1ac4..c618d3e88631073067814d2e7ee624377f6e0617 100644 (file)
@@ -2628,8 +2628,8 @@ asmlinkage void vmx_vmexit_handler(struct cpu_user_regs *regs)
     {
         HVMTRACE_1D(VMMCALL, v, regs->eax);
         inst_len = __get_instruction_length(); /* Safe: VMCALL */
-        if(hvm_do_hypercall(regs) == 0)        /* not preempted */
-            __update_guest_eip(inst_len);
+        if ( !hvm_do_hypercall(regs) )
+            __update_guest_eip(inst_len); /* preempted */
         break;
     }
     case EXIT_REASON_CR_ACCESS: